using System;
using Cysharp.Threading.Tasks;
using Spine.Unity;
using UnityEngine;

[Serializable]
public class SkeletonTouchUtilityEvent
{
    [Header("动画事件")] public bool playLoopAni;
    public int trackIndex = 0;
    public string loopAni;
    public string playAni;
    public string nextAni;
    public bool setEmptyBefore;//设置先前的动画为空

    public bool disableTouch;//关闭交互，只能播放一个动画事件的时候
    
    public void Invoke(SkeletonGraphic role)
    {
        if (playLoopAni)
        {
            role.PlayLoop(trackIndex,loopAni,setEmptyBefore);
        }
        else
        {
            if (disableTouch)
            {
                RoleTouchManager.Instance.EnableTouch = false;
                role.PlayOnce(trackIndex,playAni, nextAni,setEmptyBefore).OnComplete(() =>
                {
                    RoleTouchManager.Instance.EnableTouch = true;
                }).Forget();
            }
            else
            {
                role.PlayOnce(trackIndex,playAni, nextAni,setEmptyBefore).Forget();
            }
            
        }
    }
}